gusucode.com > VC++ 汽配销售管理系统(Access)源码程序 > VC++ 汽配销售管理系统(Access)源码程序/源码/DSellQuery.cpp

    //Download by http://www.NewXing.com
// DSellQuery.cpp : implementation file
//

#include "stdafx.h"
#include "qpglxt.h"
#include "DSellQuery.h"
#include "externDllHeader.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CQpglxtApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CDSellQuery dialog

CDSellQuery::CDSellQuery(CWnd* pParent /*=NULL*/)
	: CDialog(CDSellQuery::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDSellQuery)
	//}}AFX_DATA_INIT
}

void CDSellQuery::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDSellQuery)
	DDX_Control(pDX, IDC_STAToolTextBottom, m_StaToolTextBottom);
	DDX_Control(pDX, IDC_STAToolTextTop, m_StaToolTextTop);
	DDX_Control(pDX, IDC_STAToolText, m_StaToolText);
	DDX_Control(pDX, IDC_GRID2, m_Grid2);
	DDX_Control(pDX, IDC_GRID1, m_Grid1);
	DDX_Control(pDX, IDC_EDTCondition, m_EdtCondition);
	DDX_Control(pDX, IDC_DATE2, m_Date2);
	DDX_Control(pDX, IDC_DATE1, m_Date1);
	DDX_Control(pDX, IDC_COMField, m_ComField);
	DDX_Control(pDX, IDC_COMEmblem, m_ComEmblem);
	DDX_Control(pDX, IDC_BUTQUERY, m_ButQuery);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDSellQuery, CDialog)
	//{{AFX_MSG_MAP(CDSellQuery)
	ON_BN_CLICKED(IDC_BUTQUERY, OnButquery)
	ON_NOTIFY(NM_DBLCLK, IDC_GRID1, OnDblclkGrid1)
	ON_WM_CTLCOLOR()
	ON_BN_CLICKED(IDC_BUTPrint, OnBUTPrint)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDSellQuery message handlers

void CDSellQuery::OnOK() 
{
	// TODO: Add extra validation here
	
	//CDialog::OnOK();
}

void CDSellQuery::OnButquery() 
{
	CString sField,sEmblem,sCondition,sSQL,sDate1,sDate2,cFieldType;
	m_ComField.GetWindowText(sField);
	m_ComEmblem.GetWindowText(sEmblem);
	m_EdtCondition.GetWindowText(sCondition);
	m_Date1.GetWindowText(sDate1);
	m_Date2.GetWindowText(sDate2);
	CString abc=m_ComField.m_CurrentFieldType;
	if(m_ComField.m_CurrentFieldType=="字符型")
	{
		if(sEmblem=="LIKE")
			sSQL.Format("SELECT * from %s WHERE %s %s '%s%%' AND 时间 BETWEEN #%s# AND #%s#",m_DataBaseName,sField,sEmblem,sCondition,sDate1,sDate2);
		else
			sSQL.Format("SELECT * from %s WHERE %s %s '%s' AND 时间 BETWEEN #%s# AND #%s#",m_DataBaseName,sField,sEmblem,sCondition,sDate1,sDate2);
	}
	if(m_ComField.m_CurrentFieldType=="数值型")
		sSQL.Format("SELECT * from %s WHERE %s %s %s AND 时间 BETWEEN #%s# AND #%s#",m_DataBaseName,sField,sEmblem,sCondition,sDate1,sDate2);				
	if(m_ComField.m_CurrentFieldType=="日期型")
		sSQL.Format("SELECT * from %s WHERE %s %s #%s# AND 时间 BETWEEN #%s# AND #%s#",m_DataBaseName,sField,sEmblem,sCondition,sDate1,sDate2);				
	rst.Open(sSQL,adCmdText);
	m_Grid1.AddCellValue(rst);		
}

void CDSellQuery::SetCaption(CString sCaption)
{
	m_Caption=sCaption;
}



void CDSellQuery::SetDateBase(CString sDateBaseName)
{
	m_DataBaseName=sDateBaseName;
}

BOOL CDSellQuery::OnInitDialog() 
{
	CDialog::OnInitDialog();
	CString ToolText;
	m_StaToolText.SetBkColor(RGB(92,92,92));
	m_StaToolText.SetTextColor(RGB(255,255,255));
	m_StaToolText.SetTextSize(12);
	m_ComField.m_CurrentFieldType="文本";
	ToolText.Format("用户在右上方输入查询字段及查询条件,单击〖查询〗按钮,系统会将符合条件的概要%s信息显示在绿色的表格中。用户可以双击某条概要%s信息查询对应的详细%s信息。详细%s信息显示在粉色的表格中。",m_DataBaseName.Mid(0,m_DataBaseName.GetLength()-4),m_DataBaseName.Mid(0,m_DataBaseName.GetLength()-4),m_DataBaseName.Mid(0,m_DataBaseName.GetLength()-4),m_DataBaseName.Mid(0,m_DataBaseName.GetLength()-4));
	m_StaToolText.SetWindowText(ToolText);
	SetWindowText(m_Caption);
	m_Grid1.ReadOnly(true);
	m_Grid1.SetDataBase(m_DataBaseName,adCmdTable);
	CString sWaterBook,sToolTextTop,sToolTextBottom;
	sToolTextTop="概要"+m_DataBaseName.Mid(0,m_DataBaseName.GetLength()-4)+"信息";
	sToolTextBottom="详细"+m_DataBaseName.Mid(0,m_DataBaseName.GetLength()-4)+"信息";
	this->m_StaToolTextTop.SetWindowText(sToolTextTop);
	this->m_StaToolTextBottom.SetWindowText(sToolTextBottom);
	sWaterBook=m_DataBaseName.Mid(0,m_DataBaseName.GetLength()-4)+"明细查询";
	m_Grid1.SetBkColor(RGB(233,255,215));
	m_Grid1.SetTextBkColor(RGB(233,255,215));
	CString sSQL;
	if(m_DataBaseName=="进货查询"|| m_DataBaseName=="销售退货查询")
		sSQL.Format("SELECT 票号,往来单位,仓库,合计数量,合计金额,实付金额,未付金额,找零,经手人,操作员 FROM %s",m_DataBaseName);
	else
		sSQL.Format("SELECT 票号,往来单位,仓库,合计数量,合计金额,实收金额,未收金额,找零,经手人,操作员 FROM %s",m_DataBaseName);

	rst.Open(sSQL,adCmdText);
	m_Grid2.ReadOnly(true);
	m_Grid2.SetDataBase(sWaterBook,adCmdTable);
	m_Grid2.SetBkColor(RGB(255,215,233));
	m_Grid2.SetTextBkColor(RGB(255,215,233));
	m_Grid2.DeleteAllItems();
	m_ComField.SetFieldset(rst);
	m_ComEmblem.SetCurSel(0);
	m_ComField.SetCurSel(0);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDSellQuery::OnDblclkGrid1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	RxRecordset rRst;
	CString sSQL,sText,TableName;
	if(m_Grid1.GetHotItem()<0)
		return;
	m_HotItem=m_Grid1.GetHotItem();
	TableName=m_DataBaseName.Mid(0,m_DataBaseName.GetLength()-4)+"明细查询";
	sText=this->m_Grid1.GetItemText(m_Grid1.GetHotItem(),0);
	sSQL.Format("SELECT* FROM %s WHERE 票号='%s'",TableName,sText);
	rRst.Open(sSQL,adCmdText);
	m_Grid2.AddCellValue(rRst);
	*pResult = 0;

}

HBRUSH CDSellQuery::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	

	// TODO: Return a different brush if the default is not desired
	return hbr;
}

void CDSellQuery::OnBUTPrint() 
{
	CString sName,sDate,sCliect,sSumMoney,sBigMoney,sSumNumber,sID;
	RxRecordset brst;
	brst.Open("系统设置表");
	sName=brst.GetFieldValue("公司名称");
	sName=sName+m_DataBaseName.Mid(0,m_DataBaseName.GetLength()-4)+"单";
	sDate=this->m_Grid1.GetItemText(m_HotItem,1);	
	sCliect=this->m_Grid1.GetItemText(m_HotItem,2);	
	sSumMoney=this->m_Grid1.GetItemText(m_HotItem,5);
	sSumNumber=this->m_Grid1.GetItemText(m_HotItem,4);
	sBigMoney=MoneyToChineseCode(sSumMoney);

	sID=this->m_Grid1.GetItemText(m_HotItem,0);	

	m_ps.MainCaptionFontSize=400;
	m_ps.DeckCaptionFontSize=180;
	
	m_ps.MainCaption=sName;
	m_ps.DeckCaptionNumber=3;
	m_ps.DeckCaptions[0]=m_DataBaseName.Left(4)+"编号:"+sID;
	m_ps.DeckCaptions[1]=m_DataBaseName.Mid(0,m_DataBaseName.GetLength()-4)+"日期:"+sDate;
	m_ps.DeckCaptions[2]="往来单位:"+sCliect;
	m_ps.Grid=&m_Grid2;
	
	m_ps.TotalNumber=3;
	m_ps.Totals[0]="合计金额(小写):"+sSumMoney;
	m_ps.Totals[2]="合计数量:"+sSumNumber; 
	m_ps.Totals[1]="合计金额(大写):"+sBigMoney;
	theApp.Print();	
		
}